<!DOCTYPE html>
<html>

	<head lang="en">
		<title>找攻略</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
		<link rel="stylesheet" href="/css/reset.css"/>
		<link rel="stylesheet" href="/css/myStrategyComment.css"/>
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<script src="/js/plugins/form/jquery.form.js"></script>
		<script src="/js/common.js"></script>
		<script>
            $(function () {
                //热门标签

                $.get('/strategy/'+getParams().id+"/tags",function (data) {
                    var tags={list:data}
                    $(".tag").renderValues(tags)
                })


				//点击星星
                var starNum;
				$(".star i").click(function () {
                   starNum=$(this).data("starnum");
                   var starArr= $(".star i");
                   $(starArr).removeClass("fa-star").addClass("fa-star-o");
                    for(var i=0;i<starNum;i++){
                       $(starArr[i]).removeClass("fa-star-o").addClass("fa-star");
				   }
                })

				var img;
				//点击图片
				$(".imgs .rect").click(function () {
				    img=$(this);
                    $("#fileForm input[name='file']").click();
                })
				//提交图片后把图片显示到原图片的位置
                $("#fileForm input[name='file']").change(function () {
                    if ($(this).val()) {
                        $("#fileForm").ajaxSubmit(function (data) {
                         	img.html('<img src="'+data.url+'" width="100%">');
                        })
                    }
                })

				//解决数组作为参数提交时参数名会拼上[]的问题
                jQuery.ajaxSettings.traditional = true;

				$("#submitBtn").click(function () {
                    //comment对象
                    var comment={};
                    //星星数量
                    comment.starNum=starNum;
                    //文本内容
                    comment.content=$(".tag textarea[name='content']").val();
                    //图片
                    var imgArr=$(".imgs img");
                    var temp="";
                    for(var i=0;i<imgArr.length;i++){
                        temp+=$(imgArr[i]).attr("src")+";";
					}
                    comment.imgUrls=temp;

                    //推荐的标签
					var tags=[];
                    var activeTags=$(".tag label.active input");
                    for(var i=0;i<activeTags.length;i++){
                        tags.push($(activeTags[i]).val());
					}
					//自定义的标签
					var myTags =$(".tag input[name='myTags']").val().split(" ");
                    console.log(myTags);
                    for(var i=0;i<myTags.length;i++){
                        if (myTags[i] != "") {
                            tags.push(myTags[i])
                        }
					}
                    comment.tags=tags;

                    $.post('/strategy/'+getParams().id+'/comments',comment,function (data) {
                        if (data.success) {
                            $(document).dialog({
                                overlayClose: true,
                                content: '保存成功',
                            });
                          location.href="/strategyCatalogs.html?id="+getParams().id;
                        }else{
                            $(document).dialog({
                                overlayClose: true,
                                content: data.msg,
                            });
						}
                    })

                })

            })
		</script>
	</head>

	<body>

	<div class="search-head">
		<div class="row nav-search">
			<div class="col">
				<a href="javascript:window.history.go(-1)">
					<span><i class="fa fa-chevron-left" ></i></span>
				</a>

			</div>
			<div class="col">
				<span>点评</span>
			</div>

			<div class="col"></div>
		</div>
	</div>

	<div class="comment">
		<div class="container star">
			<p>你对该旅游地的评价</p>
			<i class="fa fa-star-o fa-lg" data-starnum="1" style="color: orange"></i>
			<i class="fa fa-star-o fa-lg" data-starnum="2" style="color: orange"></i>
			<i class="fa fa-star-o fa-lg" data-starnum="3" style="color: orange"></i>
			<i class="fa fa-star-o fa-lg" data-starnum="4" style="color: orange"></i>
			<i class="fa fa-star-o fa-lg" data-starnum="5" style="color: orange"></i>
		</div>
		<hr />
		<div class="container tag">
			<p>请为该旅游地选择合适的标签（大家都在评）</p>
			<div class="btn-group-toggle" data-toggle="buttons" render-loop="list">
				<label class="btn btn-outline-danger " >
					<input type="checkbox" autocomplete="off" render-value="list.name" >
					<div render-html="list.name"></div>
				</label>

			</div>

			<p>添加你自己的标签</p>
			<input name="myTags" class="form-control"  placeholder="请使用空格隔开标签"   />

			<p>更多评价内容</p>
			<textarea name="content" class="form-control" rows="5" placeholder="请填写你对该旅游地的评价"></textarea>
		</div>
		<div class="container imgs ">
			<p>上传图片</p>

			<div class="row">
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
			</div>
			<form id="fileForm" action="/images" method="post" enctype="multipart/form-data" style="display: none">
				<input type="file" name="file">
			</form>
		</div>
	</div>


	<div class="operation">
		<button class="btn" onclick="window.history.go(-1)">放弃评价</button>
		<button class="btn" id="submitBtn">提交评价</button>
	</div>





	</body>


</html>